package com.icexxx.icemock.util;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;

public class IceMockUtil {
	public static List<String> split(String str) {
		List<String> list = new ArrayList<>();
		List<String> result = new ArrayList<>();
		String[] split = str.split("\\+");

		for (int i = 0; i < split.length; i++) {
			String item = split[i];
			list.add(item);
		}
		String current = "";
		if (list.size() > 0) {
			current = list.get(0);
		}
		for (int i = 1; i < list.size(); i++) {
			String item = list.get(i);
			if (current.endsWith("*")) {
				current = StrUtil.removeSuffix(current, "*");
				current += "+" + item;
			} else {
				result.add(current);
				current = "";
				current += item;
			}
		}
		result.add(current);
		list.clear();
		for (int i = 0; i < result.size(); i++) {
			String item = result.get(i);
			if (StrUtil.isNotBlank(item)) {
				String trim = StrUtil.trim(item);
				list.add(trim);
			}
		}
		return list;
	}
	
	public static String genWord(String wordHoneycomb, int wordHoneycombLength, String cactus) {
		String randomChinese = null;
		for (int i = 0; i < 100; i++) {
			int randomInt = RandomUtil.randomInt(wordHoneycombLength);
			randomChinese = wordHoneycomb.substring(randomInt, randomInt + 1);
			if (cactus.contains(randomChinese)) {
				continue;
			} else {
				break;
			}
		}
		return randomChinese;
	}
}
